package com.egao.texasHoldEmPoker.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.texasHoldEmPoker.entity.Desk;
import com.egao.texasHoldEmPoker.service.DeskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;


/**
 *
 * 赌桌
 * @author : Doman
 * @date : 2022-01-26 12:39:26
 * @version ：1.0
 */

@Api(tags = "赌桌")
@RestController
@RequestMapping("/api/texasHoldEmPoker/desk")
public class DeskController extends BaseController {

	@Autowired
	private DeskService deskService;

	/**
	 * 分页查询列表
	 */
//	@PreAuthorize("hasAuthority('texasHoldEmPoker:desk:list')")
    //@OperLog(value = "赌桌", desc = "分页查询")
    @ApiOperation(value ="分页查询赌桌",notes = "" +
        "limit:每页显示几行 必填\n" +
        "page:第几页 必填\n" +
        " \n\n\n" +
        "返回的结果:\n" +
        "id:id\n" +
        "name:赌桌名称\n" +
        "increasePosition:加码\n" +
        "state:0未开始  1开始\n" +
        "blind: 小盲位置 1 \n" +
        "nextPosition: 当前下注人1\n" +
        "poker1:牌1\n" +
        "poker2:牌2\n" +
        "poker3:牌3\n" +
        "poker4:牌4\n" +
        "poker5:牌5\n" +
        "remark:备注\n" +
        "orderNum:排序\n" +
        "createTime:创建时间\n" +
        "createUser:创建人\n" +
        "updateTime:更新时间\n" +
        "updateUser:更新人\n" +
        "",httpMethod = "GET")
    @ApiPageParam
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, Desk desk) throws Exception{
        return deskService.list(page, desk, getLoginUser());
    }


    /**
     * 查询全部赌桌
     */
//    @PreAuthorize("hasAuthority('texasHoldEmPoker:desk:list')")
    //@OperLog(value = "赌桌", desc = "查询全部")
    @ApiOperation("查询全部赌桌")
    @GetMapping()
    public JsonResult list(Desk desk){
        return deskService.list(desk, getLoginUser());
    }

    /**
     * 根据id查询赌桌
     */
//    @PreAuthorize("hasAuthority('texasHoldEmPoker:desk:list')")
    //@OperLog(value = "赌桌", desc = "根据id查询")
    @ApiOperation("根据id查询赌桌")
    @GetMapping("/get")
    public JsonResult get(Desk desk) {
        return deskService.getById(desk);
		// 使用关联查询
        //PageParam<desk> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<desk> records = deskService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加赌桌
     */
//    @PreAuthorize("hasAuthority('texasHoldEmPoker:desk:save')")
    @OperLog(value = "赌桌", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加赌桌",notes = "" +
            "name:赌桌名称\n" +
            "increasePosition:加码\n" +
            "blind: 小盲位置 1 \n" +
            "nextPosition: 当前下注人1\n" +
            "poker1:牌1\n" +
            "poker2:牌2\n" +
            "poker3:牌3\n" +
            "poker4:牌4\n" +
            "poker5:牌5\n" +
            "remark:备注\n" +
            "orderNum:排序\n" +
        "",httpMethod = "POST")
    @PostMapping()
    public JsonResult save(Desk desk) {
        return deskService.save(desk, getLoginUser());
    }

    /**
     * 修改赌桌
     */
//    @PreAuthorize("hasAuthority('texasHoldEmPoker:desk:update')")
    @OperLog(value = "赌桌", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改赌桌",notes = "" +
            "id:id\n" +
            "name:赌桌名称\n" +
            "increasePosition:加码\n" +
            "state:0未开始  1开始\n" +
            "blind: 小盲位置 1 \n" +
            "nextPosition: 当前下注人1\n" +
            "poker1:牌1\n" +
            "poker2:牌2\n" +
            "poker3:牌3\n" +
            "poker4:牌4\n" +
            "poker5:牌5\n" +
            "remark:备注\n" +
            "orderNum:排序\n" +
        "",httpMethod = "PUT")
    @PutMapping()
    public JsonResult update(Desk desk) {
        return deskService.update(desk, getLoginUser());
    }

    /**
     * 删除赌桌
     */
//    @PreAuthorize("hasAuthority('texasHoldEmPoker:desk:remove')")
    @OperLog(value = "赌桌", desc = "删除", result = true)
    @ApiOperation(value ="删除赌桌",notes = "" +
      "id:id\n" +
      "",httpMethod = "POST")
    @DeleteMapping("/remove")
    public JsonResult remove(Desk desk ) {
        return deskService.remove(desk, getLoginUser());
    }

    /**
     * 批量添加赌桌
     */
    /**@RequiresPermissions("texasHoldEmPoker:desk:save")
    @OperLog(value = "赌桌", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<Desk> list) {
        if (deskService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改赌桌
     */
    /**@RequiresPermissions("texasHoldEmPoker:desk:update")
    @OperLog(value = "赌桌", desc = "批量修改", result = true)
    @ResponseBody
    @PutMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<Desk> batchParam) {
        if (batchParam.update(deskService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除赌桌
     */
    /**@RequiresPermissions("texasHoldEmPoker:desk:remove")
    @OperLog(value = "赌桌", desc = "批量删除", result = true)
    @ResponseBody
    @DeleteMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (deskService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
